﻿//*****************************************************************************
//
//  Copyright 2008 IT Cloud Company
//
//  This software is available under the Microsoft Public License.  Please
//  read the license agreement at http://opensource.org/licenses/ms-pl.html
//  before using the software.
//
//  Authors:
//    Don Song (don@itcloud.com)
//
//*****************************************************************************

using System;
using System.Collections.Generic;
using System.Text;

namespace HeadLinx.AD.Common
{
    public static class HeadLinxUtility
    {
        public static void GetUserStats(HeadLinxUser user, out int userCount, out int selectedUserCount)
        {
            if (user == null)
            {
                throw new ArgumentException("user cannot be null", "user");
            }

            userCount = 1;

            if (user.SelectedUser)
            {
                selectedUserCount = 1;
            }
            else
            {
                selectedUserCount = 0;
            }

            foreach(HeadLinxUser child in user.DirectReports.Values)
            {
                int childUserCount, childSelectedUserCount;

                // Recursively do the same for children.
                GetUserStats(child, out childUserCount, out childSelectedUserCount);

                userCount += childUserCount;
                selectedUserCount += childSelectedUserCount;
            }
        }
    }
}
